package com.nwpu.server.learning.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nwpu.server.learning.dao.SelectDao;
import com.nwpu.server.learning.entity.SelectEntity;
import com.nwpu.server.learning.service.SelectService;
import com.nwpu.server.learning.util.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@Service("SelectService")
@Slf4j
public class SelectServiceImlpl extends ServiceImpl<SelectDao, SelectEntity> implements SelectService {
    @Resource
    private SelectDao selectDao;


    @Override
    public List<Map<String, Object>> start(SelectEntity select) {
        String firstEntity = select.getFirstEntity();
        String secondEntity = select.getSecondEntity();
        String firstClassification = select.getFirstClassification();
        String secondClassification = select.getFirstClassification();

        QueryWrapper<SelectEntity> queryWrapper = new QueryWrapper<>();
        if (!StringUtils.isAnyBlank(firstEntity)) {
            queryWrapper.eq("first_entity", firstEntity);
        }
        if (!StringUtils.isAnyBlank(secondEntity)) {
            queryWrapper.eq("second_entity", secondEntity);
        }
        if (!StringUtils.isAnyBlank(firstClassification)) {
            queryWrapper.and(wrapper -> wrapper.eq("first_classification", firstClassification).or().eq("second_classification", secondClassification));
        }

        List<Map<String, Object>> maps = selectDao.selectMaps(queryWrapper);
        return maps;
    }

    /**
     * 查询第一个条件
     * @return
     */
    @Override
    public List<String> selectFirst() {
        return selectDao.selectFirst();
    }

    /**
     * 查询第二个条件
     * @return
     */
    @Override
    public List<String> selectSecond(String first) {
        return selectDao.selectSecond(first);
    }

    /**
     * 查询第三个条件
     * @return
     */
    @Override
    public List<SelectEntity> getFileName(String first, String second) {
        return selectDao.getFileName(first, second);
    }


}
